require("../css/commCss/normalize.less");
require("../css/commCss/reset.less");
require("../css/commCss/property.less");
require("../css/commCss/basic.less");
require("../fonts/iconfont.css");
require("../css/mine.less");

//导入util
const util = require("../util/util");

//axios请求
const axios = require("axios");

//导入weui
require("weui");
const weui = require("weui.js");

document.addEventListener("DOMContentLoaded", function () {
  /* 获取元素 */
  let imgurl = document.querySelector("#imgurl");
  let nickname = document.querySelector("#nickname");
  let sign = document.querySelector("#sign");
  let loginOut = document.querySelector("#loginOut");
  let dynamicCount = document.querySelector("#dynamicCount");
  let times = document.querySelector("#times");
  let calorie = document.querySelector("#calorie");

  /*1. 底部导航 */
  util.fixBottomNav("mine");

  //2.获取用户id
  let userId = localStorage.getItem("userId");

  axios.get("http://139.9.177.51:8099/users/mysportsBadge?userId=" + userId)
    .then(function (res) {
      let user = res.data.data.user;
      let sports = res.data.data.sports;
      console.log(res);
      //渲染数据
      //头像地址
      if (user.imgurl) {
        imgurl.src = user.imgurl;
      }

      //昵称
      nickname.textContent = user.nickname;

      //签名
      if (user.sign) {
        sign.textContent = user.sign;
      }
      //个人动态
      dynamicCount.textContent = res.data.data.dynamicCount;

      //总运动时间
      times.textContent = sports.times;

      //本周消耗卡路里
      calorie.textContent = sports.calorie;
    });

  //退出登录--清除本地存储,跳转到登录页面
  loginOut.addEventListener("click", function () {
    weui.confirm("您确定要退出吗？", function () {
      //清除本地存储
      localStorage.clear();
      //跳转到登录页面
      location.href = "./login.html";
    });
  });

  //点击user,跳转页面
  document.querySelector("#user").addEventListener("click", function () {
    location.href = "./personalData.html";
  });

  //点击data,跳转页面
  document.querySelector("#data").addEventListener("click", function () {
    location.href = "./sportData.html";
  });

  //点击badge,跳转页面
  document.querySelector("#badge").addEventListener("click", function () {
    location.href = "./badge.html";
  });
});
